Skip to content

fix: resolve panic when adding list entry before existing one#495

Open
ChristopherJHart wants to merge 1 commit intoCiscoDevNet:mainfrom
ChristopherJHart:fix/issue-1379-route-map-list-index-swap
Open

fix: resolve panic when adding list entry before existing one#495
ChristopherJHart wants to merge 1 commit intoCiscoDevNet:mainfrom
ChristopherJHart:fix/issue-1379-route-map-list-index-swap

Conversation

@ChristopherJHart
Copy link
Copy Markdown
Collaborator

Summary

  • The getDeletedItems (RESTCONF) and addDeletedItemsXML (NETCONF) code generator template had swapped i/j loop indices in list-attribute diff branches, causing a panic when a new list entry is inserted before an existing one
  • Fixed at 4 sites in gen/templates/model.go (2 functions x 2 nesting levels), then regenerated all affected model files via make gen
  • Affects any resource with list entries containing list-type sub-attributes — iosxe_route_map, iosxe_crypto_pki, iosxe_radius_server, and iosxe_system

Root Cause

In addDeletedItemsXML and getDeletedItems, the outer loop iterates state.Entries with index i, and the inner loop searches data.Entries for a matching key, yielding index j. Scalar attribute checks correctly used state[i] and data[j], but list-type attribute diff branches had them swapped:

// Bug: data uses state's index, state uses data's index
data.Entries[i].MatchIpAddressPrefixLists.ElementsAs(ctx, &dataValues, false)
state.Entries[j].MatchIpAddressPrefixLists.ElementsAs(ctx, &stateValues, false)

When a new entry with a lower sequence number is added (e.g., seq 500 before existing seq 1000), the existing entry shifts to a higher index in data.Entries, making j > i. Since state.Entries still has len = i + 1, accessing state.Entries[j] panics with index out of range.

// Fix: each variable uses its own index
data.Entries[j].MatchIpAddressPrefixLists.ElementsAs(ctx, &dataValues, false)
state.Entries[i].MatchIpAddressPrefixLists.ElementsAs(ctx, &stateValues, false)

The bug was introduced in getDeletedItems by commit 1ac6d2a3 (2023-09-20) and copied into addDeletedItemsXML by commit 2b9d4955 (2025-11-09).

Reproduction

Verified on both protocol paths using C8000V devices running IOS-XE 17.15:

Step Action Result
1 Deploy route map with single entry at seq 1000 using match_ip_address_prefix_lists Success (Create path)
2 Add new entry at seq 500 (lower than existing) Panic on both RESTCONF (getDeletedItems:5392) and NETCONF (addDeletedItemsXML:6436)
3 Re-apply with fixed provider binary Success on both protocols

Test plan

  • Reproduced panic on RESTCONF (C8000V, getDeletedItems)
  • Reproduced panic on NETCONF (C8000V, addDeletedItemsXML)
  • Verified fix resolves both protocol paths
  • Run full acceptance test suite (make test)

🤖 AI Generation Metadata

  • AI Generated: Yes
  • AI Tool: claude-code
  • AI Model: opus-4.6
  • AI Contribution: ~100% (root cause analysis, reproduction, fix, and verification)
  • AI Reason: bug fix — swapped loop indices in code generator template
  • Human Oversight: Code reviewed and approved by @ChristopherJHart

🤖 Generated with Claude Code

The getDeletedItems (RESTCONF) and addDeletedItemsXML (NETCONF) template
functions had swapped loop indices when comparing list-type attributes
within list entries. When i iterates state and j is the matched index in
data, the code incorrectly read data[i] and state[j], causing an
index-out-of-range panic whenever j > len(state)-1 (i.e., a new entry
is inserted before an existing one).

Fixed at both nesting levels in both functions (4 sites total in
gen/templates/model.go). Affects iosxe_route_map, iosxe_crypto_pki,
iosxe_radius_server, and iosxe_system generated models.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AI-Generated: yes
AI-Tool: claude-code
AI-Model: opus-4.6
AI-Percent: 50
AI-Reason: fix swapped i/j indices in list-diff template
@ChristopherJHart ChristopherJHart force-pushed the fix/issue-1379-route-map-list-index-swap branch from e02e374 to 7dda581 Compare April 27, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant